/* eslint-disable no-useless-escape */
/**
 * @function 检测邮箱是否输入正确
 * @param {*} s
 * @return {boolean}
 * **/
export const isEmail = (s) => {
  return /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s);
}

/**
 * @function 检测手机号是否输入正确
 * @param {*} s
 * @return {boolean}
 */
export const isMobile = (s) => {
  return /^1[0-9]{10}$/.test(s);
};

/**
 * @function 检测密码是否输入正确
 * @param {*} s
 * @return {boolean}
 * **/
export const isPassword = (s) => {
  // 密码长度在8-20位之间(必须包含数字，且字母和特殊字符至少包含一种)
  return /^(?=.*[0-9])(?=.*[a-zA-Z~!@#$%^&*()_+`\-={}|\[\]\\:";'<>?,./])[0-9a-zA-Z~!@#$%^&*()_+`\-={}|\[\]\\:";'<>?,./]{8,20}$/.test(s)
}

/**
 * @function 检测身份证号码
 * @param {*} s
 * @return {boolean}
 * **/
export const isIdNo = (s) => {
  return /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/.test(s)
}

/**
 * @function 检测是否为网络链接
 * @param {*} s
 * @return {boolean}
 * **/
export const isUrl = (s) => {
  return /^http[s]?:\/\/.*/.test(s);
}
